#include "comm.hpp"

using namespace std;

int main()
{
    // 创建信道
    Init init;
    // 打开信道
    int fd = open(FILE_FIFO, O_RDONLY);     // 只读的方式打开
    if(fd < 0)
    {
        cout << "server open fifo_file error" << endl;
        exit(FIFO_OPEN_ERR);
    }
    cout << "server open fifo_file success" << endl;

    // 开始通信
    while (true)
    {
        char buffer[1024] = {0};
        int x = read(fd, buffer, sizeof(buffer));
        if(x > 0)
        {
            buffer[x] = 0;
            cout << "I am server, client say# " << buffer << endl;
        }
        else if(x == 0)
        {
            cout << "client quit, me too" << endl;
            break;
        }
        else
            break;
    }
    close(fd);
    // 结束之后自动退出管道
    return 0;
}